package red.stu.mc.mod.codeblock.util;

import net.minecraft.block.Block;
import net.minecraft.client.resources.I18n;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;

public class LanguageTool {
	
	/**
	 * 回去显示名
	 * @param key 对应名
	 * @param parameters Object 对应放置值，为Block或Item时自动再次转义
	 * @return
	 */
	public static String getDispalyName(String key, Object ... parameters) {
		for (int i = parameters.length - 1; i >= 0; i--) {
			Object obj = parameters[i];
			if (obj == null)
				continue;
			if (obj instanceof Block)
				parameters[i] = getDispalyName((Block) obj);
			else if (obj instanceof ItemStack)
				parameters[i] = getDispalyName((ItemStack) obj);
			else if (obj instanceof Item)
				parameters[i] = getDispalyName((Item) obj);
		}
		return I18n.format(key, parameters);
	}
	
	public static String getDispalyName(Block block) {
		return I18n.format(block.getUnlocalizedName() + ".name");
	}
	
	public static String getDispalyName(Item item) {
		return I18n.format(item.getUnlocalizedName() + ".name");
	}
	
	public static String getDispalyName(ItemStack stack) {
		return I18n.format(stack.getUnlocalizedName() + ".name");
	}
	
}
